package com.swlz.servlet;

import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.Random;

import javax.imageio.ImageIO;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.swlz.Const;

import cn.hutool.captcha.CaptchaUtil;
import cn.hutool.captcha.ShearCaptcha;

/**<pre>
 * - 
 * ClassName : com.swlz.servlet.CodeSerlvet
 * Author : swlz
 * E-Mail : 2233875735@qq.com
 * Date : 2020年8月4日 下午3:30:14
 * Version : 1.0
 * Copyright 2020 swlz.top Inc. All rights reserved. 
 * Warning: this content is only for internal circulation of the company. 
 * It is forbidden to divulge it or use it for other commercial purposes.
 * </pre>
 **/
@WebServlet("/code.let")
public class CodeSerlvet extends HttpServlet {

	@Override
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		int width = 200;
		int height = 100;
		int len = 4;
		try {
			width = Integer.valueOf(request.getParameter("w"));
		}catch(Exception e){
			
		}
		
		try {
			height = Integer.valueOf(request.getParameter("h"));
		}catch(Exception e){
			
		}
		
		try {
			len = Integer.valueOf(request.getParameter("len"));
		}catch(Exception e){
			
		}
		
		//生成验证码
		ShearCaptcha captcha = CaptchaUtil.createShearCaptcha(width, height, len, 4);
		//获取验证码内容
		request.getSession().setAttribute(Const.CODE_NAME, captcha.getCode());
		response.reset();//清除空白行
		response.setContentType("image/png");
		captcha.write(response.getOutputStream());
		response.flushBuffer();
	}
}
